package cn.itcast.usermanage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.itcast.usermanage.pojo.DatagridResult;
import cn.itcast.usermanage.pojo.PageResult;
import cn.itcast.usermanage.pojo.User;
import cn.itcast.usermanage.service.UserService;

/**
 * @author fw847
 *
 */
/**   
*    
* 项目名称：usermanager   
* 类名称：UserController   
* 类描述：   
* 创建人：fw847   
* 创建时间：2018年3月8日 上午9:38:17   
* @version        
*/
@Controller("userController")
@RequestMapping("page")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	/**
	* @Title: webpage
	* @Description: TODO(这是一个 静态的页面展示 )
	* @param @param WebpageName
	* @param @return    参数
	* @return String    返回类型
	* @throws
	*/
	@RequestMapping("{WebpageName}")
	public String webpage(@PathVariable("WebpageName") String WebpageName){
		System.out.println("页面展示的是 : "+ WebpageName);
		return WebpageName;
	}
	
	@RequestMapping(value="/list", method = RequestMethod.GET)
	@ResponseBody
	public DatagridResult<User> userList(@RequestParam(value="page",defaultValue="1")Integer page,
			@RequestParam(value="rows",defaultValue="5")Integer rows) {
		
		DatagridResult<User> datagridResult = userService.userList(page,rows);
		return datagridResult;
	}
	
	
	/**
	* @Title: exportExcel
	* @Description: TODO(这是一个EXCEL表导出  )
	* @param @param page
	* @param @param rows
	* @param @return    参数
	* @return ModelAndView    返回类型
	* @throws
	*/
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView exportExcel(@RequestParam(value="page",defaultValue="1")Integer page,
			@RequestParam(value="rows",defaultValue="5")Integer rows) {
		ModelAndView mv = new ModelAndView("excelView");
		
		DatagridResult<User> userList = userService.userList(page, rows);
		
		mv.addObject("excelData",userList);
		
		return mv;
	}
	
	
}
















